<?
	// permohonan cuti khusus
	include("../lib/config.php");
	$nik 		= $HTTP_GET_VARS['nik'];
	$jenis_cuti = $HTTP_GET_VARS['jenis_cuti'];
	$no			= $HTTP_GET_VARS['no'];
	$tahun		= $HTTP_GET_VARS['tahun'];
	$cuti		= $HTTP_GET_VARS['cuti'];
	
	// CUTI KHUSUS
	if($cuti == "khusus"){
	$sql = mssql_query("SELECT * FROM VCuti WHERE id='$no'",$conn);
	$row = mssql_fetch_array($sql);

	// get data from karir ptsi (Tanggal Masuk)
	$sawalkarir = mssql_query("SELECT CONVERT(CHAR(12), tgl_efektif, 103) TglEfektif FROM VKarirPtsi WHERE NIK='".$nik."' ORDER BY seqno ASC",$conn);
	$rawalkarir = mssql_fetch_array($sawalkarir);	
	
	// get data from karir ptsi
	$skarptsi = mssql_query("SELECT * FROM VKarirPtsi WHERE NIK='$nik' ORDER BY seqno DESC",$conn);
	$rkarptsi = mssql_fetch_array($skarptsi);
	
	if(empty($rkarptsi[kode_so1])){
		$kodeso =$rkarptsi[kode_so2];
	}
	else{
		$kodeso =$rkarptsi[kode_so1];
	}
	 
	$sql9 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'",$conn);
	$row9 = mssql_fetch_array($sql9);
	//echo"<td>";
	if(empty($row9[uraian])){
		//echo"&nbsp;";
		$unitkerja = "&nbsp;";
	}
	else{
		//echo"$row9[uraian]";
		$unitkerja = $row9[uraian];
	}
	
	if(empty($rkarptsi[jabatan1])){
		$jabatan =$rkarptsi[jabatan2];
	}
	else{
		$jabatan =$rkarptsi[jabatan1];
	}
	
	$sjab 		= mssql_query("SELECT * FROM MstJabatan WHERE kode='$jabatan'",$conn);
	$rjab 		= mssql_fetch_array($sjab);
	$njabatan	= $rjab[nama];
	}
	
	

	// CUTI TAHUNAN
	elseif($cuti == "tahunan"){
	$sql = mssql_query("SELECT CONVERT(CHAR(12),tgl_cuti, 103) TglAwal, CONVERT(CHAR(12),tgl_selesai,103) TglAkhir, * FROM VCutiTahunan WHERE NIK='".$nik."' AND id='".$no."'",$conn);
	$row = mssql_fetch_array($sql);
	
	// get data from karir ptsi (Tanggal Masuk)
	$sawalkarir = mssql_query("SELECT CONVERT(CHAR(12), tgl_efektif, 103) TglEfektif FROM VKarirPtsi WHERE NIK='".$nik."' ORDER BY seqno ASC",$conn);
	$rawalkarir = mssql_fetch_array($sawalkarir);	
	
	// get data from karir ptsi
	$skarptsi = mssql_query("SELECT * FROM VKarirPtsi WHERE NIK='".$nik."' ORDER BY seqno DESC",$conn);
	$rkarptsi = mssql_fetch_array($skarptsi);
	
	//if(empty($rkarptsi[kode_so1])){
		$kodeso =$rkarptsi[kode_so2];
	//}
	//else{
		//$kodeso =$rkarptsi[kode_so1];
	//}
	if(!empty($kodeso)){ 
		$sql9 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'",$conn);
		$row9 = mssql_fetch_array($sql9);
		//echo"<td>";
		if(empty($row9[uraian])){
			//echo"&nbsp;";
			$unitkerja = "&nbsp;";
		}
		else{
			//echo"$row9[uraian]";
			$unitkerja = $row9[uraian];
		}
	}
	
	//if(empty($rkarptsi[jabatan1])){
		$jabatan =$rkarptsi[jabatan2];
	//}
	//else{
	//	$jabatan =$rkarptsi[jabatan1];
	//}
	if(!empty($jabatan)){
	$sjab 		= mssql_query("SELECT * FROM MstJabatan WHERE kode='$jabatan'",$conn);
	$rjab 		= mssql_fetch_array($sjab);
	$njabatan	= $rjab[jabatan];
	}
	// jatah cuti tahunan
	$gj = mssql_query("SELECT jatah_cuti, syarat_waktu FROM VJCuti WHERE nama='Cuti Tahunan'",$conn);
	$rj = mssql_fetch_array($gj);
	$jatah_cuti = $rj[jatah_cuti];
	$syarat_cuti= $rj[syarat_waktu];

	// untuk mengetahui jumlah cuti pada periode tersebut
	$sgc	= mssql_query("SELECT count(*) jumlah FROM CutiTahunan WHERE NIK='".$nik."' AND periode='".$row[periode]."' AND aktif='A' AND aktif IN ('A',NULL) AND (ambil='1' OR tunda='0')",$conn);
	$rgc 	= mssql_fetch_array($sgc);
	
	//echo "dsd".$rgc[jumlah];
	
	if($rgc[jumlah] == 0){
		// get sisa cuti
		$sisa_cuti = $jatah_cuti;
		if($rgc[jumlah] == NULL){
			$jumlah_cuti = 0;
		}
		else{
			$jumlah_cuti = $rgc[jumlah];
		}
	}
	else{
		// get sisa cuti jika cuti pada periode ini diambil
		$sisa_cuti 	= $jatah_cuti - $rgc[jumlah];	
		if($rgc[jumlah] == NULL){
			$jumlah_cuti = 0;
		}
		else{
			$jumlah_cuti = $rgc[jumlah];
		}
	}
	}
	
	// CUTI BESAR
	elseif($cuti == "besar"){
	//$sql = mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY periode) AS No, CONVERT(CHAR(12), tgl_awal, 103) TglAwal, CONVERT(CHAR(12), tgl_akhir, 103) TglAkhir, A.NIK,B.Nama,jml_cuti,id FROM Cuti A, VLatestKarir B WHERE A.NIK=B.NIK AND A.NIK='$nik' AND periode='".$HTTP_GET_VARS['periode']."' ) SELECT * FROM limit WHERE id='$no'",$conn);
	$sql = mssql_query("SELECT CONVERT(CHAR(12), tgl_awal, 103) TglAwal, CONVERT(CHAR(12), tgl_akhir, 103) TglAkhir, A.NIK,B.Nama,jml_cuti,* FROM Cuti A, VLatestKarir B WHERE A.NIK=B.NIK AND id='$no'",$conn);
	$row = mssql_fetch_array($sql);
	
	// get data from karir ptsi
	$sawalkarir = mssql_query("SELECT CONVERT(CHAR(12), tgl_efektif, 103) TglEfektif FROM VKarirPtsi WHERE NIK='".$nik."' ORDER BY seqno ASC",$conn);
	$rawalkarir = mssql_fetch_array($sawalkarir);	
	
	$skarptsi = mssql_query("SELECT * FROM VLatestKarir WHERE NIK='$nik'");
	$rkarptsi = mssql_fetch_array($skarptsi);
	
	if(empty($rkarptsi[kode_so1])){
		$kodeso =$rkarptsi[kode_so2];
	}
	else{
		$kodeso =$rkarptsi[kode_so1];
	}
	 
	$sql9 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'",$conn);
	$row9 = mssql_fetch_array($sql9);
	//echo"<td>";
	if(empty($row9[uraian])){
		//echo"&nbsp;";
		$unitkerja = "&nbsp;";
	}
	else{
		//echo"$row9[uraian]";
		$unitkerja = $row9[uraian];
	}
	
	if(empty($rkarptsi[jabatan1])){
		$jabatan =$rkarptsi[jabatan2];
	}
	else{
		$jabatan =$rkarptsi[jabatan1];
	}
	
	if(empty($jabatan)){
	}
	else{
		$sjab 		= mssql_query("SELECT * FROM MstJabatan WHERE kode='$jabatan'",$conn);
		$rjab 		= mssql_fetch_array($sjab);
		$njabatan	= $rjab[nama];
	}
	// jatah cuti besar
	$gj = mssql_query("SELECT jatah_cuti, syarat_waktu FROM VJCuti WHERE nama='Cuti Besar'",$conn);
	$rj = mssql_fetch_array($gj);
	$jatah_cuti = $rj[jatah_cuti];
	$syarat_cuti= $rj[syarat_waktu];

	// untuk mengetahui jumlah cuti pada periode tersebut
	$sgc	= mssql_query("SELECT sum(jml_cuti) jumlah FROM Cuti WHERE id_JenisCuti='2' AND NIK='".$nik."' AND periode='".$row[periode]."' AND aktif='A'",$conn);
	$rgc 	= mssql_fetch_array($sgc);
	
	if($rgc[jumlah] == 0){
		// get sisa cuti
		$sisa_cuti = $jatah_cuti;
		if($rgc[jumlah] == NULL){
			$jumlah_cuti = 0;
		}
		else{
			$jumlah_cuti = $rgc[jumlah];
		}
	}
	else{
		// get sisa cuti jika cuti pada periode ini diambil
		$sisa_cuti 	= $jatah_cuti - $rgc[jumlah];	
		if($rgc[jumlah] == NULL){
			$jumlah_cuti = 0;
		}
		else{
			$jumlah_cuti = $rgc[jumlah];
		}
	}
	}

?>
<style type="text/css">
	body,table{
		font-size:11px;
		font-family:Verdana, Arial, Helvetica, sans-serif;
	}
</style>
<title>Permohonan Cuti</title>
<table width="80%" align="center">
 <tr>
  <td align="center"><b><h2>PERMOHONAN CUTI</h2></b></td>
 </tr>
 <tr>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td>Dengan ini saya,
   <table align="left" border="0">
    <tr>
     <td width="100">Nama:</td>
     <td width="200"><?=$row[Nama]?></td>
    </tr>
    <tr>
     <td>NIK:</td>
     <td><?=$row[NIK]?></td>
    </tr>
    <tr>
     <td>Jabatan:</td>
     <td><?=$njabatan?></td>
    </tr>    
    <tr>
     <td>Unit Kerja/Divisi/Biro:</td>
     <td><?=$unitkerja?></td>
    </tr> 
    <tr>
     <td>Tanggal Masuk:</td>
     <td><?=$rawalkarir[TglEfektif]?></td>
    </tr> 
   </table>
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td>Mengajukan permohonan cuti :<Br /><br />
  <div align="center">
  <?
  	if($cuti == "tahunan"){
  ?>
  Cuti Tahunan
  <?
  	}
	elseif($cuti == "khusus"){
  ?>
  Cuti Khusus
  <?	
	}
	elseif($cuti == "besar"){
  ?>
  Cuti Besar
  <?
    }
  ?>
   mulai tanggal <?=$row[TglAwal]?> s/d <?
   if($cuti == "tahunan"){
   	echo $row[TglAwal];
   }
   else{
    echo $row[TglAkhir];
   }
   ?> ( <?
   if($cuti == "tahunan"){
    echo "1";
   }
   else{
  	echo $row[jml_cuti];
   }
   ?>
   
    hari kerja ).<br /><br />
  </div>
  <!--Alamat selama cuti berlangsung <br />
  ............................................................................................................................<Br />
  ............................................................................................................................<br />
  ............................................................................................................................<Br />
  ............................................................................................................................<br />
  ............................................................................................................................<Br />
  ............................................................................................................................<br />
  -->
<br /><br /><br /><br /><br />
	<table width="80%" cellpadding="0" cellspacing="0" align="center">
 	 <tr>
  	  <td width="80%">Menyetujui,<br />Direksi/GM/DGM/Ka.Cab/Ka. SBU/Ka. Div</td>
  	  <td width="20%">Jakarta, <?=date("d/m/Y")?><br />Pegawai ybs.</td>
 	 </tr>
     <tR height="150">
      <td valign="bottom">
      _________________________________<br />
      NIK :
      </td>
      <td valign="bottom">
      <u><?=$row[Nama]?></u><br />
      NIK: <?=$row[NIK]?>
      </td>
     </tR>
     
     <tr>
      <td colspan="2"><bR /><bR />
      Catatan Direksi/GM/DGM/Ka.Cab/Ka. SBU/Ka. Div<br /><br />
  ............................................................................................................................<Br />
  ............................................................................................................................<br />
  ............................................................................................................................<Br />
  ............................................................................................................................<br />
      
      </td>
     </tr>
     
	</table>
  </td>
 </tr>
 <tr>
  <td colspan="3"><br /><br />
  <fieldset>
   <legend>DIISI OLEH DIVISI SDM</legend>
   <table width="100%">
    <tr>
     <td colspan="2">Hak Cuti</td>
    </tr>
    <tr>
     <td valign="top">
      <table>
      <?
        if($cuti == "tahunan"){
	  ?>
       <tr>
        <td rowspan="3" valign="top"><input type="checkbox" /></td>
        <td>Cuti Tahunan 
        <?
        if($cuti == "tahunan"){
			echo" Periode $row[periode]";
		}
		else{
			echo" _______________";
		}
		?>
        </td>
        <td>: 
		<?
        if($cuti == "tahunan"){
			echo $jatah_cuti;
		}
		else{
			echo "...";
		}
		?>
         hari.</td>
       </tr>
       <tr>
        <td>Telah Diambil</td>
        <td>: 
		<?
        if($cuti == "tahunan")
		{
			echo $jumlah_cuti;
		}
		else{
			echo "...";		
		}
		?>
         hari.</td>
       </tr>
       <tr>
        <td>Sisa Cuti Tahunan 
		<?
        if($cuti == "tahunan"){
			echo" Periode $row[periode]";
		}
		else{
			echo" _______________";
		}
		?>
        </td>
        <td>: 
		<?
        if($cuti == "tahunan"){
			echo $sisa_cuti;
		}
		else{
			echo"...";
		}		
		?>
         hari.</td>
       </tr>
       <?
	   }
       if($cuti == "besar"){
	   ?>
       <tr>
        <td rowspan="3" valign="top"><input type="checkbox" /></td>
        <td>Cuti Besar 
        <?
        if($cuti == "besar"){
			echo" Periode Ke-".$HTTP_GET_VARS['periode']."";
		}
		else{
			echo" _______________";
		}
		?>        
        </td>
        <td>: 
		<?
        if($cuti == "besar"){
			echo $jatah_cuti;
		}
		else{
			echo "...";
		}
		?>        
         hari.</td>
       </tr>
       <tr>
        <td>Telah Diambil</td>
        <td>: 
		<?
        if($cuti == "besar")
		{
			echo $jumlah_cuti;
		}
		else{
			echo "...";		
		}
		?>        
         hari.</td>
       </tr>
       <tr>
        <td>Sisa Cuti Besar
        <?
        if($cuti == "besar"){
			echo" Periode Ke-$row[periode]";
		}
		else{
			echo" _______________";
		}
		?>                
        </td>
        <td>: 
		<?
        if($cuti == "besar"){
			echo $sisa_cuti;
		}
		else{
			echo"...";
		}		
		?>
         hari.</td>
       </tr>
       <?
       }
	   ?>
       <!--
       <tr>
        <td rowspan="3" valign="top"><input type="checkbox" /></td>
        <td>Lainnya</td>
        <td>: ... hari.</td>
       </tr>
       -->	
      </table><br /><br />
      <small>
      <i>
      * Isi dengan tanda X, sesuai dengan pilihan<br />
      * Coret yang tidak perlu
      </i>
      </small>
     </td>
     <td>
      <fieldset><legend>Catatan &amp; Paraf Adm Kepegawaian</legend>
      <table width="100%">
      <tr height="200">
       <td height="200"><br /><br /><br /><br /></td>
      </tr>
      </table>
      _______________________________<br />
      NIK:
      </fieldset>
     </td>
    </tr>
   </table>
  </fieldset>
  </td>
 </tr>
</table>